package com.loop.unclelend.ui.adapter

import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import com.loop.unclelend.R
import com.loop.unclelend.databinding.UncleItemRepayOrderDetailsBinding
import com.loop.unclelend.databinding.UncleItemRepayOrderTitleBinding
import com.loop.unclelend.utils.adapter.UncleRecyclerViewAdapter
import com.loop.unclelend.utils.adapter.UncleViewHolderHelper
import org.json.JSONObject

/**
 * UncleLend
 * @Author wwdeng
 * @CreateTime: 2024/9/27 14:42
 * @Annotation：待还款订单 适配器
 */
class Adapter_Repay_Order(recyclerView: RecyclerView?) : UncleRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.uncle_item_repay_order) {
    override fun setItemChildListener(helper: UncleViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.btn_repay) //支付
    }

    override fun fillData(helper: UncleViewHolderHelper, position: Int, model: JSONObject) {
        val titleLayout = helper.getView<LinearLayout>(R.id.layout_title)
        titleLayout.removeAllViews()
        val titleList = model.optJSONArray("titleList")
        if (titleList != null) {
            for (i in 0..<titleList.length()){
                val item = titleList.optJSONObject(i)
                val titleBinding = UncleItemRepayOrderTitleBinding.inflate(LayoutInflater.from(mContext))
                titleBinding.txtTitle.text = item.optString("showName")
                titleBinding.txtValue.text = item.optString("showDetail")
                titleLayout.addView(titleBinding.root)
            }
        }

        val contentLayout = helper.getView<LinearLayout>(R.id.layout_details)
        contentLayout.removeAllViews()
        val contentList = model.optJSONArray("contentList")
        if (contentList != null) {
            for (i in 0..<contentList.length()){
                val item = contentList.optJSONObject(i)
                val contentBinding = UncleItemRepayOrderDetailsBinding.inflate(LayoutInflater.from(mContext))
                contentBinding.txtTitle.text = item.optString("showName")
                contentBinding.txtValue.text = item.optString("showDetail")
                contentLayout.addView(contentBinding.root)
            }
        }
    }
}